package com.eduran.cotools.controller;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.TextArea;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import org.apache.commons.lang.StringEscapeUtils;
import java.net.URL;
import java.util.ResourceBundle;

public class Controller implements Initializable{

    @Override
    public void initialize(URL location, ResourceBundle resources) {}

    @FXML private Button htmlBtnConvert;
    @FXML private Button htmlBtnReverse;
    @FXML private Button htmlBtnCopy;
    @FXML private Button unicodeBtnConvert;
    @FXML private Button unicodeBtnReverse;
    @FXML private Button unicodeBtnCopy;
    @FXML private TextArea htmlTextArea;
    @FXML private TextArea unicodeTextArea;

    public void htmlConvert(){
        StringBuffer strHTMLInput = new StringBuffer();
        strHTMLInput.append(htmlTextArea.getText());
        htmlTextArea.setText(StringEscapeUtils.escapeHtml(String.valueOf(strHTMLInput)));
    }
    public void htmlReverse(){
        StringBuffer strHTMLInput = new StringBuffer();
        strHTMLInput.append(htmlTextArea.getText());
        htmlTextArea.setText(StringEscapeUtils.unescapeHtml(String.valueOf(strHTMLInput)));
    }
    public void unicodeConvert(){
        StringBuffer strUnicodeInput = new StringBuffer();
        strUnicodeInput.append(unicodeTextArea.getText());
        unicodeTextArea.setText(StringEscapeUtils.escapeJava(String.valueOf(strUnicodeInput)));
    }
    public void unicodeReverse(){
        StringBuffer strUnicodeInput = new StringBuffer();
        strUnicodeInput.append(unicodeTextArea.getText());
        unicodeTextArea.setText(StringEscapeUtils.unescapeJava(String.valueOf(strUnicodeInput)));
    }
    public void htmlCopy(){
        StringBuilder strHTMLInput = new StringBuilder();
        strHTMLInput.append(htmlTextArea.getText());
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(strHTMLInput.toString());
        clipboard.setContent(content);
    }
    public void unicodeCopy(){
        StringBuilder strUnicodeInput = new StringBuilder();
        strUnicodeInput.append(unicodeTextArea.getText());
        Clipboard clipboard = Clipboard.getSystemClipboard();
        ClipboardContent content = new ClipboardContent();
        content.putString(strUnicodeInput.toString());
        clipboard.setContent(content);
    }
    public void action(){

    }
}
